package com.heima.article.feign;

import com.heima.article.service.ArticleCommentService;
import com.heima.article.service.ArticleService;
import com.heima.feign.article.IArticleClient;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.comment.pojos.CommentSaveDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmCommentDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ArticleClient implements IArticleClient {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private ArticleCommentService articleCommentService;
    /**
     * 保存app端相关文章方法
     * @param articleDto
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult savaOrUpdate(@RequestBody ArticleDto articleDto) {
       return articleService.saveArticle(articleDto);
    }

    /**
     * 上架文章，保存到es
     *
     * @param articleId
     * @return
     */
    //todo 上架文章到es
    @PostMapping("/api/v1/article/{articleId}")
    public ResponseResult rackArticleSaveToES(@PathVariable Long articleId) {
       return articleService.getArticleToES(articleId);
    }

    /**
     * 通过文章id得到作者信息
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/articleInfo")
    public ResponseResult getArticleInfo(@RequestBody CommentSaveDto dto) {
        return articleService.getAuthorInfo(dto);
    }

    /**
     * 通过用户id得到文章i信息
     * @param userId
     * @return
     */
    @Override
    @PostMapping("/api/v1/wemediaComment/{userId}")
    public PageResponseResult getArticle(@PathVariable("userId") Integer userId, @RequestBody WmCommentDto dto) {
        return articleCommentService.getArticleInfo(userId,dto);
    }

    /**
     * 一段时间内文章的信息
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/newsDimension")
    public ResponseResult newsDimension(@RequestBody WmCommentDto dto) {
        return articleService.newsDimension(dto);
    }

    /**
     * 分页展示文章列表，展示当前时间范围内的具体文章阅读、评论、收藏的数量。
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/newsPage")
   public PageResponseResult newsPage(@RequestBody WmCommentDto dto){
        return articleService.newsPage(dto);
    }
}
